package com.panshi.repast.JsonAppbean;

import java.util.List;

import org.apache.http.NameValuePair;

import android.os.Handler;
import android.os.Message;

import com.panshi.repast.Http.DataLoaderTask;
import com.panshi.repast.Http.DataLoaderTask.DataCallback;

/**
 * 获取网络json数据
 * 
 * @author huang
 * 
 */
public class GetHttpJson<T> {
	
	private Class<T> t = null;
	private Handler handler = null;
	
	/**
	 * 构造函数
	 * 
	 * @param t
	 * @param handler
	 */
	public GetHttpJson(Class<T> t,Handler handler){
		this.t = t;
		this.handler = handler;
	}

	/**
	 * 获取网络数据
	 * 
	 * @param url
	 * @param params
	 */
	public void Http(String url, List<NameValuePair> params) {
		DataLoaderTask.getInstance().loadData(callback, url, params);
	}

	/**
	 * json数据获取接口
	 */
	DataLoaderTask.DataCallback callback = new DataCallback() {

		@Override
		public void dataCallback(int dataStatus, String mValue) {
			Message msg = new Message();
			String error = null;
			String value = null;
			if (dataStatus == 1) {
				error = "获取数据失败！请稍后再试";
				value = "null";
			} else if (dataStatus == 2) {
				error = "请检查网络！";
				value = "null";
			} else {
				msg.obj = GetJsonAppean.getInstance().getJsonAppbean(mValue, t); 
			}
			handler.sendMessage(msg);
		}
	};

}
